#include "node_bp.h"

namespace ann
{

const double node_bp::tick(const double* pInVec, const UINT pInCnt)
{
    assert( pInCnt == m_inCnt );

    this->SaveInVec(pInVec);
    
    //cal sum of product
    double tSum = 0.0;
    for( UINT i = 0; i < m_inCnt; ++i )
    {
        tSum += pInVec[i]*m_weight[i];
    }
    tSum += m_b;

    m_data = m_exFunc(tSum);

    return m_data;
}

const UINT node_bp::UpdateW(const double pAlpha, const double pDelta)
{
    double tVal = 0.0;

    for( UINT i = 0; i < m_inCnt; ++i )
    {
        tVal = pAlpha * pDelta * m_inVec[i];
        m_weight[i] += tVal;
    }

    tVal = pAlpha * pDelta;
    m_b += tVal;

    return eann_Normal;
}

}
